
prices = [7,1,5,3,6,4]

var maxProfit = function(prices) {
    let maxprofit=0
    let min=Infinity
    for(let i=0;i<prices.length;i++)
    {
        if(prices[i]<min){
            min=prices[i]
        }
        else if(prices[i]-min>maxprofit)
        {
             maxprofit=prices[i]-min
        }
    }
       return maxprofit

};



console.log(maxProfit(prices))